package org.huntaway.lucene.document;

import java.io.File;
import java.io.IOException;

import org.apache.lucene.document.Document;
import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.index.IndexWriter;
import org.huntaway.kernel.NutException;
import org.huntaway.lucene.po.BaseLucene;

public abstract class BaseDocument<T extends BaseLucene> {
	protected Document doc = null;

	protected abstract void setBackField(File fileName);
	protected abstract void setAnalyzerField(File fileName);
	public Document document(File fileName)
			throws java.io.FileNotFoundException {
		doc=new Document();
		setBackField(fileName);
		setAnalyzerField(fileName);
		return doc;
	}

	//
	/**
	 * @param file
	 * @param luceneBean
	 * @throws CorruptIndexException
	 * @throws IOException
	 * @throws NutException
	 */
	public void addDocument(IndexWriter indexWriter,File file)
			throws CorruptIndexException, IOException, NutException {
		indexWriter.addDocument(document(file));
	}
}
